using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using GoodStuff;

namespace GoodStuff
{
    class GoodTextBox : IGoodControl
    {
        IGoodProperty _label;

        public IGoodProperty Label {
            get { return _label; }
            set { _label = value; _textBox.Text = _label.ToString(); }
        }


        IGoodProperty _text;

        public IGoodProperty Text {
            get { return _text; }
            set { _text = value; _textBox.Text = _text.ToString(); }
        }

        IGoodProperty _width;

        public IGoodProperty Width {
            get { return _width; }
            set { _width = value; }
        }

        TextBox _textBox;

        IGoodProperty _updateTextKey;

        public IGoodProperty UpdateTextKey {
            get { return _updateTextKey; }
            set { _updateTextKey = value; }
        }

        public void UpdateText(object sender, SampleEventArgs args) {
            _text.Set(args.Sample[_updateTextKey.ToString()].ToString());
            _textBox.Text = args.Sample[_updateTextKey.ToString()].ToString();
        }

        protected void OnTextChanged(object sender, EventArgs args) 
        {
            _textBox.Text = _text.ToString();
        }

        public  GoodTextBox() 
        {
            Trace.WriteLine("Initializing GoodTextBox");
            _text = (IGoodProperty)new GoodProperty<string>();
            _text.Set("Default");

            _textBox = new TextBox();
            _textBox.TextAlign = HorizontalAlignment.Left;
            _textBox.Text = _text.ToString();
            _textBox.TextChanged += OnValueChanged;

        }

        protected void OnValueChanged(object sender, EventArgs e) 
        {
        }


        #region IGoodControl Members

        public Control Control {
            get { return _textBox; }
        }

        public void Initialize() {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion
    }
}
